import java.util.Stack;
     //最小栈
public class Solution2 {
    class MinStack {
        public Stack<Integer> stack;
        public Stack<Integer> minstack;
        public MinStack() {
            stack = new Stack<>();
            minstack = new Stack<>();
        }

        public void push(int val) {
            stack.push(val);
            if(minstack.empty()) {
                minstack.push(val);
            }else {
                int topVal = minstack.peek();
                if(val <= topVal) {
                    minstack.push(val);
                }
            }
        }

        public void pop() {
            int val = stack.peek();
            if(val == minstack.peek()) {
                minstack.pop();
            }
            stack.pop();
        }

        public int top() {
            return stack.peek();
        }

        public int getMin() {
            if(minstack.empty()) return -1;
            return minstack.peek();
        }
    }
}
